// 菱形继承解决

#include <iostream>
#include <string>

// 车 -> 汽车/电车 -> 特斯拉

class Vehicle // 车
{
public:
    Vehicle(const std::string &category)
        : _category(category)
    {
        std::cout << "Vehicle()" << std::endl;
    }

    ~Vehicle()
    {
        std::cout << "~Vehicle()" << std::endl;
    }

    const std::string& getCategory() const
    {
        return _category;
    }

private:
    std::string _category; // 种类
};

class Car : virtual public Vehicle // 汽车
{
public:
    Car(const int &displacement = 0, bool isBelong = false, const std::string &name = "")
        : Vehicle("car"), _isBelong(isBelong), _name(name)
    {
        if (isBelong)
        {
            _displacement = displacement;
        }
        std::cout << "Car()" << std::endl;
    }

    ~Car()
    {
        std::cout << "~Car()" << std::endl;
    }

    const std::string& getName() const
    {
        return _name;
    }

    const int& getDisplacement() const
    {
        return _displacement;
    }

private:
    int _displacement; // 排量
    bool _isBelong;    // 是否属于
    std::string _name; // 车名
};

class Tramcar : virtual public Vehicle // 电车
{
public:
    Tramcar(const int &capacitance = 0, bool isBelong = false, const std::string &name = "")
        : Vehicle("tramcar"), _isBelong(isBelong), _name(name)
    {
        if (isBelong)
        {
            _capacitance = capacitance;
        }
        std::cout << "Tramcar()" << std::endl;
    }

    ~Tramcar()
    {
        std::cout << "~Tramcar()" << std::endl;
    }

    const std::string& getName() const
    {
        return _name;
    }

    const int& getCapacitance() const
    {
        return _capacitance;
    }

private:
    int _capacitance;  // 电容量
    bool _isBelong;    // 是否属于
    std::string _name; // 车名
};

class Tesla : public Car, public Tramcar // 特斯拉车
{
public:
    Tesla(std::string name)
        : Car()
        , Tramcar(3000, true, "tesla")
        , Vehicle("tramcar")
        , _name(name)
    {
        _name += "-telsa";
        std::cout << "Tesla()" << std::endl;
        printf("namae: %s, capacitence : %d, category: %s\n", _name.c_str(), getCapacitance(), getCategory().c_str());
    }

    ~Tesla()
    {
        std::cout << "~Tesla()" << std::endl;
    }

private:
    std::string _name;
};

int main()
{
    Tesla("ModelS");
    return 0;
}
